package org.example.Service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.example.Dao.AddressDao;
import org.example.Dao.DeliveryDao;
import org.example.Pojo.Address;
import org.example.Pojo.Delivery;
import org.example.Service.DeliveryService;
import org.example.Utils.UnionResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class DeliverServiceImpl implements DeliveryService {
    @Resource
    DeliveryDao deliveryDao;
    @Resource
    AddressDao addressDao;
    @Override
    public UnionResult GetDeliveryInfo(String ordersid,String addressid) {
        QueryWrapper<Delivery> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("ordersid", ordersid);
        List<Delivery> deliveryList = deliveryDao.selectList(queryWrapper);
        Address address = addressDao.selectOne(new QueryWrapper<Address>().eq("uid",addressid));
        Object[] objects = new Object[]{deliveryList,address};
        return UnionResult.Success("",objects);
    }

    @Override
    public UnionResult addDeliveryInfo(Delivery delivery) {
        delivery.setDates(new Date());
        if (deliveryDao.insert(delivery) > 0) {
            return UnionResult.Success();
        }else{
            return UnionResult.Failure();
        }
    }
}
